﻿using System;
using System.IO;
using System.Text;

namespace SomeKit.Serialization
{
    public static partial class SerializationHelper
    {
        public static T Deserialize<T>(this string graph, Func<Stream, T> objectReader)
        {
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(graph)))
            {
                var theObject = objectReader(stream);
                return (T)theObject;
            }
        }

        public static T DeserializeXml<T>(this string graph)
        {
            return graph.Deserialize(ReadObjectFromXmlStream<T>);
        }

        public static T DeserializeJson<T>(this string graph)
        {
            return graph.Deserialize(ReadObjectFromJsonStream<T>);
        }
    }
}
